/*
 * Copyright(c)  2022 厦门外里科技有限公司 All rights reserved.
 *
 * https://www.wailikeji.com
 *
 * 版权所有，侵权必究！
 */

import {
	createRouter
} from 'uni-simple-router';

import store from '@/common/store'

//初始化
const router = createRouter({
	APP: {
		animation: {
			animationType: 'pop-in',
			animationDuration: 300
		}
	},
	encodeURI: false, //加密路由
	platform: process.env.VUE_APP_PLATFORM,
	routes: [...ROUTES]
});

//全局路由前置守卫
router.beforeEach((to, from, next) => {
	// console.log('前置守卫Yoooooooooo')
	console.log('页面跳转', to)
	console.log('页面来自于', from)

	// 有两个个判断条件,一个是token,还有一个路由元信息
	let tokenFlag = store.getters.loginFlag;
	console.log("tokenFlag:" + tokenFlag)
	if (to.path != '/pages/login/login') {
		uni.setStorageSync('fromLogin', {
			path: to.path,
			query: to.query
		})
	}

	if (to.meta && to.meta.auth && !tokenFlag) {
		console.log('我要登录');
		next('/pages/login/login');
	} else {
		console.log('正常跳转页面');
		next();
	}

})

// 全局路由后置守卫
router.afterEach((to, from) => {

})

export default router;
